﻿Imports Biblioteca
Imports System.Data.SqlClient

Public Class Form2

    Dim var As New Class1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        var.adapter.Fill(var.midataset, "Tabla1")
        DataGridView1.DataSource = var.midataset
        DataGridView1.DataMember = "Tabla1"

        TextBox3.Text = DataGridView1.RowCount - 1

        ComboBox1.DataSource = var.midataset.Tables("Tabla1")
        ComboBox1.DisplayMember = "Apellidos"
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim cb As New SqlDataAdapter
        Dim comando As New SqlCommand
        comando = New SqlCommand(("Select * from Tabla1 where Apellidos=@apellidos"), var.conexion)
        Dim ds As New DataSet
        cb.SelectCommand = comando
        comando.Parameters.Add("@apellidos", SqlDbType.VarChar, 15).Value = ComboBox1.Text
        ds.Clear()
        cb.Fill(ds, "Tabla1")
        DataGridView1.DataSource = ds
        TextBox3.Text = DataGridView1.RowCount - 1
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim comando As SqlCommand
        comando = New SqlCommand(("Select * from Tabla1 where Apellidos like '%" & TextBox1.Text & "%'"), var.conexion)
        var.adapter.SelectCommand = comando
        var.midataset.Clear()
        var.adapter.Fill(var.midataset, "Tabla1")
        DataGridView1.DataSource = var.midataset
        TextBox3.Text = DataGridView1.RowCount - 1
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

    End Sub
End Class